package com.demo.web.controller;

import com.demo.common.utils.JsonResult;
import com.demo.common.utils.RedisUtil;
import com.demo.domain.dto.UserDTO;
import com.demo.service.MpUserService;
import com.demo.web.config.RabbitMQConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @author A
 */
@Slf4j
@RestController
@RequestMapping("/test")
public class TestController {

	@Resource
	private MpUserService mpUserService;

	@Resource
	private RedisUtil redisUtil;

	@Resource
	private RabbitTemplate rabbitTemplate;


	@PostMapping("/test")
	public JsonResult test(@RequestBody @Valid UserDTO user) {
		System.out.println(user.toString());
		return JsonResult.ok();
	}

	@GetMapping("/sendMsg")
	public JsonResult sendMsg(String msg, String key) {
		log.info("[sendMsg]-msg={},key={}", msg, key);
		rabbitTemplate.convertAndSend(RabbitMQConfig.ITEM_TOPIC_EXCHANGE, key, msg);
		return JsonResult.ok();
	}

	@GetMapping("/sendTtlMsg")
	public JsonResult sendTtlMsg() {
		rabbitTemplate.convertAndSend("ttl_queue", "send ttl_queue 10s");
		return JsonResult.ok();
	}


}
